﻿$(document).ready(function () {
    //$("#subContent .leftNav").load("/OperationManage/Tree");
    $("#subNav span").eq(0).addClass("selectedNav");

    //加载树形，树形加载后会自动加载第一个span项目对应的内容
    ajaxLoad("#subContent .leftNav", "/OperationManage/Tree");

    //点击span项目后
    $("#subNav span").click(function () {
        var index = $("#subNav span").index($(this));
        loadContent(index);
    });
});

function loadContent(index) {
    $("#subNav span").removeClass("selectedNav");
    $("#subNav span").eq(index).addClass("selectedNav");

    //$("#subContent .rightContent").load($("#subNav span").eq(index).attr("data-href"));
    var selector = "#subContent .rightContent";
    var url = $("#subNav span").eq(index).attr("data-href");
    //取得筛选条件
    var treeObj = $.fn.zTree.getZTreeObj("tree");
    var nodeId = treeObj.getSelectedNodes()[0].id;

    url = url + '?id=' + nodeId;
    ajaxLoad(selector, url);
}


function loadFailed() {
    $("#errorPic").show();
}

function loadComplete() {
    registertableevent();

    $("#pagerDiv a").click(function () {
        //给searchform添加pageIndex参数
        if ($(this).attr("disabled") == "disabled") {
            return false;
        }
        $("<input type='hidden' name='pageIndex' id='pageIndex' value='" + $(this).attr("value") + "' />").insertAfter("#searchForm span:last");

        $("#searchForm").submit();
    });


    $("#pagerDiv select").change(function () {
        $("<input type='hidden' name='pageIndex' id='pageIndex' value='" + $(this).val() + "' />").insertAfter("#searchForm span:last");

        $("#searchForm").submit();
    });
}